package com.ebupt.migu.music.iop.controller;

import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.iop.pojo.dto.IopTagDto;
import com.ebupt.migu.music.iop.service.IopTagService;
import com.ebupt.migu.music.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author tz
 */
@Slf4j
@RestController
@RequestMapping("/iopTag")
public class IopTagController {

    @Resource
    private IopTagService iopTagService;
    @Resource
    private HttpServletRequest request;
    
    /**
     *  标签树
     * @return
     */
    @GetMapping("/tagsTree")
    public ResultObject tagsTree() {
        return iopTagService.tagsTree();
    }

    /**
     *  修改信息
     * @return
     */
    @PostMapping("/updateIopTag")
    public ResultObject updateIopTag(@RequestBody IopTagDto dto) {
        return iopTagService.updateIopTag(dto);
    }

    /**
     *  标签详情信息
     * @return
     */
    @GetMapping("/getIopTag")
    public ResultObject getIopTag(@RequestParam(value = "id") Integer id) {
        return iopTagService.getIopTag(id);
    }

    /**
     *  收藏标签
     * @return
     */
    @GetMapping("/collectTag")
    public ResultObject collectTag(@RequestParam(value = "tagId") String tagId) {
        SysUser sysUser = ReqestParamUtil.userInfo(request);
        return iopTagService.collectTag(sysUser,tagId);
    }

    /**
     *  取消收藏标签
     * @return
     */
    @GetMapping("/cancelCollect")
    public ResultObject cancelCollect(@RequestParam(value = "tagId") String tagId) {
        SysUser sysUser = ReqestParamUtil.userInfo(request);
        return iopTagService.cancelCollect(sysUser,tagId);
    }

    /**
     *  根据用户查询收藏列表
     * @return
     */
    @GetMapping("/qryCollect")
    public ResultObject qryCollect() {
        SysUser sysUser = ReqestParamUtil.userInfo(request);
        return iopTagService.qryCollect(sysUser);
    }

    /**
     *  签人群下拉
     * @return
     */
    @GetMapping("/qryTagUserList")
    public ResultObject qryTagUserList() {
        return iopTagService.qryTagUserList();
    }

    /**
     *  全量用户
     * @return
     */
    @PostMapping("/allCount")
    public ResultObject allCount(@RequestBody List<String> ids) {
        return iopTagService.allCount(ids);
    }
}